from django.shortcuts import render
from django.core.validators import RegexValidator
from django.core.exceptions import ValidationError
# Create your views here.
#ModelForm表单
#优点1:#重写phone字段方法
from .models import *
from django import forms
class RegModelFrom(forms.ModelForm):
    #重写phone字段方法正则匹配手机号格式,
    phone = forms.CharField(label='手机号',validators=[RegexValidator( "^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$",'手机浩格式错误')])
    #重写pwd方法,密文展示
    pwd = forms.CharField(widget=forms.PasswordInput,label='密码')
    pwds = forms.CharField(widget=forms.PasswordInput,label='重复密码')
    code = forms.CharField(label='验证码')
    class Meta:
        model = UserInfo
        fields = '__all__'
def red(request):
    form = RegModelFrom()
    return render(request,'red.html',{'form':form})